<template>
  <div class="section_common">
    <div class="main">
      <el-form ref="form" label-width="100px">
        <el-form-item label="入职人员">
          <el-input v-model="name" size="mini" @change="findExaminationByName($event)"></el-input>
        </el-form-item>
        <el-form-item label="入职部门">
          <el-input v-model="deptName" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="入职岗位">
          <el-input v-model="posName" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="初试评价">
          <el-input v-model="firstEvaluation" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="复试评价">
          <el-input v-model="secondEvaluation" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="审批人">
          <el-input v-model="approverName" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="预计到岗时间">
          <el-date-picker
            size="mini"
            v-model="expectWorkTime"
            type="date"
            placeholder="选择日期"
            :editable="false"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到岗状态">
          <el-select
            v-model="workState"
            size="mini"
            placeholder="请选择"
          >
            <el-option label="待入职" value="待入职"></el-option>
            <el-option label="未到岗" value="未到岗"></el-option>
            <el-option label="已到岗" value="已到岗"></el-option>
            <el-option label="未入职" value="未入职"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="到岗时间">
          <el-date-picker
            size="mini"
            v-model="workTime"
            type="date"
            placeholder="选择日期"
            :editable="false"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="submitPost" v-bind:disabled="isShow"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {Toast } from "vant";
export default {
  data() {
    return {
      nowUser:"",
      id:"",
      name:"",
      deptName:"",
      posName:"",
      firstEvaluation:"",
      secondEvaluation:"",
      expectWorkTime:"",
      workState:"",
      workTime:"",
      approverName:"",

      code:"",
      title:"入职审批",
      updateExamination: '/mobiles/updateExamination',
      isShow:false,
      message:"提交",

      show:false,
      workTimeShow:false,

    };
  },

  created() {
    this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
  },

  methods: {
    findExaminationByName(){
      this.$https.post('/mobiles/findExaminationByName',{
        nowUser:this.nowUser,
        name:this.name,
      }).then((res)=>{
        if (res.data.code=='500'){
          this.code=500;
          this.$toast(res.data.message);
        }else {
          this.code='';
        }
        if (res.data.code=='200'){
          this.id=res.data.data.id;
          this.deptName=res.data.data.deptName;
          this.posName=res.data.data.positionName;
          this.firstEvaluation=res.data.data.firstEvaluation;
          this.secondEvaluation=res.data.data.secondEvaluation;
          debugger
          this.expectWorkTime=res.data.data.expectWorkTime;
          this.workState=res.data.data.workState;
          this.workTime=res.data.data.workTime;
          this.approverName=res.data.data.approverName;

        }

      }).catch(err=>{
        console.log(err);
      })
    },
    // 返回
    goBack() {
      this.$router.go(-1);
    },
    // 提交
    submitPost() {

      if (!this.isNull()) return false;

      this.$https.post(this.updateExamination, {
        nowUser:this.nowUser,
        id:this.id,
        name:this.name,
        expectWorkTime:this.expectWorkTime,
        workState:this.workState,
        workTime:this.workTime,

      }).then(() => {
        Toast("推送成功");
        this.isShow=true;
        this.message="已提交";
        this.$router.go(-1);
      }).catch(err => {
        console.log(err)
      });
    },
    //判断相关数据是否为空
    isNull() {
      if (this.name == '') {
        this.$toast("姓名不能为空");
        return false;
      }
      if (this.deptName == '') {
        this.$toast("入职部门不能为空");
        return false;
      }
      if (this.posName == '') {
        this.$toast("入职岗位不能为空");
        return false;
      }
      if (this.code=='500'){
        this.$toast("不存在该用户的入职审批或无权查看,请检查");
        return false;
      }
      return true;
    },

  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-items: center;
  margin: 0 auto;
  .el-form {
    padding-right: 10px;
    .el-form-item {
      .el-form-item__label {
        line-height: 16px;
      }
      margin-bottom: 5px;
    }
  }
}
</style>